//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package wudashan.Protocol;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class ReportProcess {
    private String identifier = "123";
    private String msgType = "deviceReq";
    private int hasMore = 0;
    private int errcode = 0;
    private int brightness = 0;
    private double voltage = 0.0D;
    private int current = 0;
    private double frequency = 0.0D;
    private double powerfactor = 0.0D;
    private int temperature = 0;
    private byte bDeviceReq = 0;
    private byte bDeviceRsp = 1;
    private int mId = 1;

    public ReportProcess(byte[] binaryData) {
        this.identifier = "123";
        if (binaryData[2] == this.bDeviceReq) {
            this.msgType = "deviceReq";
            this.hasMore = binaryData[3];
        } else {
            if (binaryData[2] != this.bDeviceRsp) {
                return;
            }

            this.msgType = "deviceRsp";
            this.errcode = binaryData[3];
            this.mId = this.bytes2Int(binaryData, 4, 2);
        }

        this.brightness = binaryData[4];
        this.voltage = (double)((float)((binaryData[5] << 8) + (binaryData[6] & 255)) * 0.1F);
        this.current = (binaryData[7] << 8) + binaryData[8];
        this.powerfactor = (double)binaryData[9] * 0.01D;
        this.frequency = (double)binaryData[10] * 0.10000000149011612D + 45.0D;
        this.temperature = binaryData[11] & 127;
    }

    public ObjectNode toJsonNode() {
        try {
            ObjectMapper mapper = new ObjectMapper();
            ArrayNode arrynode = mapper.createArrayNode();
            ObjectNode brightNode = mapper.createObjectNode();
            brightNode.put("serviceId", "Brightness");
            ObjectNode brightData = mapper.createObjectNode();
            brightData.put("brightness", this.brightness);
            brightNode.put("serviceData", brightData);
            arrynode.add(brightNode);
            ObjectNode electricityNode = mapper.createObjectNode();
            electricityNode.put("serviceId", "Electricity");
            ObjectNode electricityData = mapper.createObjectNode();
            electricityData.put("voltage", this.voltage);
            electricityData.put("current", this.current);
            electricityData.put("frequency", this.frequency);
            electricityData.put("powerfactor", this.powerfactor);
            electricityNode.put("serviceData", electricityData);
            arrynode.add(electricityNode);
            ObjectNode temperatureNode = mapper.createObjectNode();
            temperatureNode.put("serviceId", "Temperature");
            ObjectNode temperatureData = mapper.createObjectNode();
            temperatureData.put("temperature", this.temperature);
            temperatureNode.put("serviceData", temperatureData);
            arrynode.add(temperatureNode);
            ObjectNode root = mapper.createObjectNode();
            root.put("identifier", this.identifier);
            root.put("msgType", this.msgType);
            if (this.msgType.equals("deviceReq")) {
                root.put("hasMore", this.hasMore);
                root.put("data", arrynode);
            } else {
                root.put("errcode", this.errcode);
                root.put("mId", this.mId);
                ObjectNode body = mapper.createObjectNode();
                body.put("result", 0);
                root.put("body", body);
            }

            return root;
        } catch (Exception var11) {
            var11.printStackTrace();
            return null;
        }
    }

    public int bytes2Int(byte[] b, int start, int len) {
        int sum = 0;
        int end = start + len;

        for(int i = start; i < end; ++i) {
            int n = b[i] & 255;
            --len;
            n <<= len * 8;
            sum += n;
        }

        return sum;
    }
}
